<?php

namespace app\modules\admin\models;

use Yii;

/**
 * This is the model class for table "role_access".
 *
 * @property int $id
 * @property int $role_id 角色id
 * @property int $access_id 权限id
 * @property int $create_at 创建时间
 */
class RoleAccess extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'role_access';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['role_id', 'access_id', 'create_at'], 'integer'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'role_id' => 'Role ID',
            'access_id' => 'Access ID',
            'create_at' => 'Create At',
        ];
    }

    public static function getSelectAccessIds($roleId)
    {
        $selectAccessIds = [];
        $roleAccessList = self::find()->where(['role_id' => $roleId])->asArray()->all();
        if ($roleAccessList) {
            $selectAccessIds = array_column($roleAccessList, 'access_id');
        }
        return $selectAccessIds;
    }
}
